package org.wak.character.display
{
	/**
	 * Data structure to contain an Animation description loaded from 
	 * the CharDisplays xml. 
	 * 
	 */	
	public class Animation
	{
		// Animation XML tag represented.
		private var mAnimXML:XML = null ;
		
		// Behaviour of the animation.
		private var mBehaviour:String = "";
		
		// The Bitmap or MovieClip should be flipped horizontally.
		private var mFlipHoriz:Boolean = false ;
		
		// The Bitmap or MovieClip should be flipped vertically.
		private var mFlipVert:Boolean = false ;
		
		// Rows of a tiled bitmap if this is the case, ignored if a Movieclip is used.
		private var mRows:int = 1;
		
		// Cols of a tiled bitmap if this is the case, ignored if a Movieclip is used.
		private var mCols:int = 1;
		
		// Id of the resource, either Bitmap or MovieClip to be used in the animation.
		private var mAnimResId:String = "" ;
		
		// horizontal offset inside the animation. 
		private var mOffsetX:Number = 0 ;
		// vertical offset inside the animation.
		private var mOffsetY:Number = 0 ;
		
		
		public function Animation(pAnimXML:XML)
		{
			mAnimXML = pAnimXML ;
			mAnimResId = mAnimXML[0] ;
			//trace(mAnimResId);
			mBehaviour = mAnimXML.@behaviour ;
			mFlipHoriz = mAnimXML.@flipHorizontal == "true"? true : false ;
			mFlipVert = mAnimXML.@flipVertical == "true" ? true : false ;
			mRows = mAnimXML.@rows ;
			mCols = mAnimXML.@cols ;	
			
			
			if( pAnimXML.@offsetx != "" )
			{
				mOffsetX = pAnimXML.@offsetx ;
			}
				
			if( pAnimXML.@offsety != "" )
			{
				mOffsetY = pAnimXML.@offsety ;
			}		
		
		}
		
		public function toString():String
		{
			return "Animation:"+ mAnimResId + " for "+ mBehaviour + " flipH:" +mFlipHoriz + " flipV:"+ mFlipVert + " Rows:"+ mRows + " Cols:"+ mCols + "\n"; 
		}
		
		/**
		 * @see AnimationBehaviour
		 * @return the behaviour id
		 * 
		 */		
		public function get behaviour():String
		{
			return mBehaviour ;
		}
		
		/**
		 * Flip Horizontal
		 * @return true if the Image or movieclip should be fliped horizontally 
		 * 
		 */		
		public function get flipH():Boolean
		{
			return mFlipHoriz ;
		}
		
		/**
		 * Flip Vertical
		 * @return true if the Image or movieclip should be fliped vertically 
		 * 
		 */		
		public function get flipV():Boolean
		{
			return mFlipVert ;
		}
		
		/**
		 * Animation Rows in the case of a tiled Bitmap 
		 * @return number of rows
		 * 
		 */		
		public function get rows():int
		{
			return mRows ;
		}
		
		/**
		 * Animation Columns in the case of a tiled Bitmap 
		 * @return number of columns
		 * 
		 */		
		public function get cols():int
		{
			return mCols ;
		}
		
		/**
		 * The id of the Bitmap or MovieClip behind this animation. 
		 * @return the id of the animation resource.
		 * 
		 */		
		public function get resourceId():String
		{
			return mAnimResId ;
		}

		/**
		 * Horizontal offset of the animation inside the character display.
		 * @return 
		 * 
		 */				
		public function get offsetX():Number
		{
			return mOffsetX ;
		}
		
		/**
		 * Vertical offset of the animation inside the character display.
		 * @return 
		 * 
		 */				
		public function get offsetY():Number
		{
			return mOffsetY ;
		}
		
		
		

	}
}